import request from "@/utils/request";
import { parseStrEmpty } from "@/utils/ruoyi";

// 获取数据源列表
export const getDatasourceLists = (params) => {
  const queryString = new URLSearchParams(params)
  return request({
    url: "/dataSource/pageList?" + queryString,
    method: "post",
    data: params,
  });
};

//数据源字典
export const getDatasourceType = () => {
  return request({
    url: "/system/dict/data/type/data_source_type",
    method: "get",
  });
};

// 新增数据源
export function addDatasource(data) {
  return request({
    url: "/dataSource/add",
    method: "post",
    data: data,
  });
}

// 编辑数据源
export function editDatasource(data) {
  return request({
    url: "/dataSource/edit",
    method: "post",
    data: data,
  });
}

// 测试连接
export function testConnection(data) {
  return request({
    url: "/dataSource/testConnection",
    method: "post",
    data: data,
  });
}

// 删除数据源
export function deleteDatasource(data) {
  return request({
    url: "/dataSource/deleteByIds",
    method: "post",
    data: data,
  });
}

//数据源编码
export const queryAllDataSource = () => {
  return request({
    url: "/dataSource/queryAllDataSource",
    method: "get",
  });
};


// 获取数据源列表
export const getDatasetLists = (params) => {
  const queryString = new URLSearchParams(params)
  return request({
    url: "/dataSet/pageList?" + queryString,
    method: "post",
    data: params,
  });
};

//dataSet/testTransform 测试数据源
export const testTransform = (data) => {
  const queryString = new URLSearchParams(data)
  return request({
    url: "/dataSet/testTransform",
    method: "post",
    data: data,
  });
};

// 新增数据集
export function addDataset(data) {
  return request({
    url: "/dataSet/add",
    method: "post",
    data: data,
  });
}

// 编辑数据集
export function editDataset(data) {
  return request({
    url: "/dataSet/edit",
    method: "post",
    data: data,
  });
}

// 删除数据集
export function deleteDataset(data) {
  return request({
    url: "/dataSet/deleteByIds",
    method: "post",
    data: data,
  });
}

// ai大屏
export const getDashboardData = () => {
  return request({
    url: "/model/getDashboardData",
    method: "get",
  });
};

//模型管理列表
export const getModelLists = (params) => {
  return request({
    url: "/model/list",
    method: "get",
    params: params,
  });
};

// 新增模型
export function addModel(data) {
  return request({
    url: "/model/add",
    method: "post",
    data: data,
  });
}

// 编辑模型
export function editModel(data) {
  return request({
    url: "/model/edit",
    method: "post",
    data: data,
  });
}

// 删除模型
export function deleteModel(ids) {
  return request({
    url: "/model/remove?ids="+ids,
    method: "post",
  });
}

//model info
export async function getModelInfo(modelId) {
  return request(`/model/getModelInfo/${modelId}`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  });
}

export async function getModelVersionInfo(modelId, modelVersionId) {
  return request(`/model/getModelVersionInfo/${modelId}/${modelVersionId}`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  });
}

// 编辑训练参数
export async function publishVersion(modelId, modelVersionId) {
  return request(`/model/publishVersion/${modelId}/${modelVersionId}`, {
    method: 'POST',
  });
}

//查询模型列表
export async function getVersionList(id, params) {
  return request(`/model/listVersionInfo/${id}`, {
    params: params,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  });
}

//查询所有数据集
export async function getQueryAllDataSetList() {
  return request('/dataSet/queryAllDataSet', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  });
}

export async function getAiSetList(params) {
  const queryString = new URLSearchParams(params).toString();
  return request(`/aiSet/list?${queryString}`, {
    data: params,
    method: 'GET',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  });
}
export async function searchOriginalList(params) {
  if (params.currSetId == 6) {
    return searchRadarList(params);
  }
  else if (params.currSetId == 7) {
    return searchPointList(params)
  }
  else if (params.currSetId == 8) {
    return searchSpectrumList(params);
  }
  else if (params.currSetId == 9) {
    return searchBackScatterList(params);
  }
  else if (params.currSetId == 10) {
    return searchBackPointList(params);
  }
}

export async function searchRadarList(params) {
  const queryString = new URLSearchParams(params).toString();
  return request(`/setOriginal/listRadar?${queryString}`, {
    data: params,
    method: 'GET',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  });
}

export async function searchSpectrumList(params) {
  const queryString = new URLSearchParams(params).toString();
  return request(`/setOriginal/listSpectrum?${queryString}`, {
    data: params,
    method: 'GET',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  });
}

export async function searchBackPointList(params) {
  const queryString = new URLSearchParams(params).toString();
  return request(`/setOriginal/listBackPoint?${queryString}`, {
    data: params,
    method: 'GET',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  });
}

export async function searchBackScatterList(params) {
  const queryString = new URLSearchParams(params).toString();
  return request(`/setOriginal/listBackScatter?${queryString}`, {
    data: params,
    method: 'GET',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  });
}

export async function getAiToolPageList(params) {
  const queryString = new URLSearchParams(params).toString();
  return request(`/aiTool/list?${queryString}`, {
    data: params,
    method: 'POST',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  });
}

export function listAiSets() {
  return request('/aiSet/listParent', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}

//根据数据集id，分页查询数据集数据
export async function getQueryDateSet(params) {
  return request('/dataSet/queryDateSet', {
    method: 'POST',
    data: params,
  });
}

//新建模型版本
export async function addVersion(params) {
  return request(`/model/addVersionInfo`, {
    data: params,
    method: 'POST',
  });
}
//编辑模型版本
export async function updateVersion(params) {
  return request(`/model/updateVersionInfo`, {
    data: params,
    method: 'POST',
  });
}

//模型管理delete
export async function removeModel(params) {
  return request(`/model/remove?ids=${params}`, {
    method: 'POST',
  });
}

//版本管理delete
export async function removeVersion(params) {
  return request(`/model/deleteVersionInfo/${params}`, {
    method: 'GET',
  });
}

export function listAiModels() {
  return request('/model/listAll', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}

export function listVersions(modelId) {
  return request('/model/listVersionInfo/' + modelId,{
    method: 'GET',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}

export async function addAiSet(params) {
  return request('/aiSet/add', {
    method: 'POST',
    data: params,
  });
}

export async function updateAiSet(params) {
  return request('/aiSet/edit', {
    method: 'POST',
    data: params,
  });
}

export async function deleteSetByIds(params) {
  return request('/aiSet/deleteByIds', {
    method: 'POST',
    data: params,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  });
}

export async function addTool(params) {
  return request('/aiTool/add', {
    method: 'POST',
    data: params,
  });
}

export async function updateTool(params) {
  return request('/aiTool/edit', {
    method: 'POST',
    data: params,
  });
}

export async function deleteToolByIds(params) {
  return request('/aiTool/deleteByIds', {
    method: 'POST',
    data: params,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  });
}

// 查询软件工厂列表
export function getFactoryLists() {
  return request(`/model/listAll`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  });
}
